//
//  AlgorithmTool.h
//  ZXLSign
//
//  Created by zxl02 on 2020/11/10.
//

#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonHMAC.h>
#import <Security/Security.h>
#import "GTMBase64.h"
#import "ZXLSignData.h"
#import "ZXLConfig.h"

NS_ASSUME_NONNULL_BEGIN
typedef NS_CLOSED_ENUM(NSInteger, SecuritySceneServiceType) {
    SecuritySceneServiceTypeEncrypt   =1  ,  //加密
    SecuritySceneServiceTypeVertify   =4  ,  //验签
    SecuritySceneServiceTypeDecrypt   =2  ,  //解密
    SecuritySceneServiceTypeSignal    =3  ,  //加签
};

typedef NS_CLOSED_ENUM(NSInteger, SecuritySignLengthAES) {
    KeySizeAES128          = 16,
    KeySizeAES192          = 24,
    KeySizeAES256          = 32,
};
//加密类型
//typedef NS_ENUM(NSInteger,SecurityEncryptType) {
//
//};
typedef NS_ENUM(NSInteger, DictionaryType) {
    DictionaryTypeKey,       // key
    DictionaryTypeValue,     // value
};
typedef NS_CLOSED_ENUM(NSInteger, SecurityResult) {
    SecurityReusltAscending , //升
    SecurityReusltDescending   //降
};
@interface AlgorithmTool : NSObject<SignProtocol>

///// md5 32位
///// @param srcString 加密字符串
///// @param isUppercase 大小写
//+ (NSString *)getMd5_32Bit_String:(NSString *)srcString isUppercase:(BOOL)isUppercase;
//
///// md5 16位
///// @param srcString 加密字符串
///// @param isUppercase 大小写
//+ (NSString *)getMd5_16Bit_String:(NSString *)srcString isUppercase:(BOOL)isUppercase;

/**
字符串SHA加密 String SHA1 encryption
@param string 要加密的字符串 String to be encrypted
@param shaType 要加密的类型  encrypte type
@param lowercase 是否小写 Is it a lowercase
@return 加密过的字符串 Encrypted string
*/
//+ (NSString *)SHAEncryptWithString:(NSString *)string withType:(SecurityDigestAlgorithmType)shaType withLowercase:(BOOL)lowercase;


@end

#pragma mark - AES
@interface ZXLSignToolAES : NSObject

/// AES 加密
/// @param plainText  加密字符串
/// @param key 秘钥
/// @param keySize 长度
+(NSString *)AESEncrypt:(NSString *)plainText key:(NSString *)key keySize:(SecuritySignLengthAES)keySize;

/// AES解密
/// @param encryptText 解密字符串
/// @param key 秘钥
/// @param keySize 长度
+(NSString *)AESDecrypt:(NSString *)encryptText key:(NSString *)key keySize:(SecuritySignLengthAES)keySize;
@end

#pragma mark - RSA
@interface ZXLSignToolRSA : NSObject

// return base64 encoded string
+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;
// return raw data
+ (NSData *)encryptData:(NSData *)data publicKey:(NSString *)pubKey;
// return base64 encoded string
+ (NSString *)encryptString:(NSString *)str privateKey:(NSString *)privKey;
// return raw data
+ (NSData *)encryptData:(NSData *)data privateKey:(NSString *)privKey;

// decrypt base64 encoded string, convert result to string(not base64 encoded)
+ (NSString *)decryptString:(NSString *)str publicKey:(NSString *)pubKey;
+ (NSData *)decryptData:(NSData *)data publicKey:(NSString *)pubKey;
+ (NSString *)decryptString:(NSString *)str privateKey:(NSString *)privKey;
+ (NSData *)decryptData:(NSData *)data privateKey:(NSString *)privKey;

/// rsa加签
/// @param plainData 加签data
/// @param PrivatKey 私钥
+ (NSData *)sha256WithRSA:(NSData *)plainData  withPrivatKey:(NSString*)PrivatKey;

/// 验签
/// @param plainData 加密的data
/// @param signature 加签的data
/// @param publicKey 公钥
+ (BOOL)rsaSHA256VertifyingData:(NSData *)plainData withSignature:(NSData *)signature  withpublicKey:(NSString*)publicKey;
@end
#pragma mark - DES 3DES
@interface ZXLSignToolDES : NSObject
///DES加密
/// @param plainText 字符串
/// @param key key
+(NSString *)encryptUseDES:(NSString *)plainText key:(NSString *)key;
///DES解密
/// @param cipherText 字符串
/// @param key key
+(NSString *)decryptUseDES:(NSString *)cipherText key:(NSString *)key;
///3DES加密
/// @param plainText 字符串
/// @param key key
+(NSString *)encryptUse3DES:(NSString *)plainText key:(NSString *)key;
///3DES解密
/// @param cipherText 字符串
/// @param key key
+(NSString *)decryptUse3DES:(NSString *)cipherText key:(NSString *)key;


////解密
//+(SignResult*)decryptionType:(SecurityEncryptType)encryptType decryptionStr:(NSString*)decryptionStr  zxlConfig:(ZXLConfig*)config;
////加密
//+(SignResult*)encryptType:(SecurityEncryptType)encryptType StringToSign:(NSString*)StringToSign  zxlConfig:(ZXLConfig*)config;

@end
NS_ASSUME_NONNULL_END
